# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

# root=TreeNode(1)
# root.left=TreeNode(2)
# root.left.left=TreeNode(3)
# root.left.right=TreeNode(4)
# root.right=TreeNode(2)
# root.right.left=TreeNode(4)
# root.right.right=TreeNode(3)
#案例过不了
root=TreeNode(5)
root.left=TreeNode(4)
root.right=TreeNode(1)
root.left.right=TreeNode(1)
root.right.right=TreeNode(4)
root.left.right.left=TreeNode(2)
root.right.right.left=TreeNode(2)

def dfs1(leftRoot,rightRoot):
    #出口条件
    if not(leftRoot or rightRoot):
        return True
    if not(leftRoot and rightRoot):
        return False
    if leftRoot.val!=rightRoot.val:
        return False
    return dfs1(leftRoot.left,rightRoot.right) and dfs1(leftRoot.right,rightRoot.left)



def isSymmetric1(root):
    if not root and (root and root.left==None and root.right==None):
        return True
    return dfs1(root.left,root.right)
print(isSymmetric1(root))






print(isSymmetric1(root))